package edu.utd.text.game.designer.commands;

import java.util.Scanner;

import edu.utd.text.game.designer.controller.DesignerController;
import edu.utd.text.game.domain.GameMap;
import edu.utd.text.game.domain.areas.Room;

public class EditRoomCommand implements DesignerCommand {

	public EditRoomCommand() {  }
	
	
	public String execute() throws Exception {
		
		Scanner scanner = new Scanner(System.in);
		System.out.println("Name of room to edit: ");
		String roomName = scanner.nextLine();
		
		GameMap map = DesignerController.INSTANCE.getGameMap(); 
		Room room = map.getRoomByName(roomName);
		
		if (null == room) {
			return "No room by the name \"" + roomName + "\" was found in the game map."; 
		}
		
		System.out.println("New room name (default: \"" + roomName + "\").");
		String newRoomName = scanner.nextLine();
		if (newRoomName.equals("") || newRoomName.isEmpty()) {
			newRoomName = roomName;
			System.out.println("Room name unchanged.");
		}
		room.setRoomName(newRoomName);
		
		System.out.println("New room description: default:\n=============== \n\""
				+ room.getDescription() + "\"\n===============");
		String newDescription = scanner.nextLine();
		if (newDescription.equals("") || newDescription.isEmpty()) {
			newDescription = room.getDescription();
			System.out.println("Room description unchanged.");
		}
		room.setDescription(newDescription);
		
		return "Done editing room: " + room.getRoomName();
	}

}
